package kr.hkit.powerjava.chapter18;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;
import javax.swing.JSpinner;

import java.awt.FlowLayout;
import java.util.Calendar;
import java.util.Date;

import javax.swing.BoxLayout;
import javax.swing.JColorChooser;

public class SpinnerTest extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SpinnerTest frame = new SpinnerTest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SpinnerTest() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 205, 139);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		
		//ListModel
		String[] items = {"소설", "잡지", "전공서적", "취미"};
		SpinnerListModel listModel = new SpinnerListModel(items); // 모델
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		JSpinner spinner_ListModel = new JSpinner(listModel); //스피너
		contentPane.add(spinner_ListModel);
		
		//NumberModel
		SpinnerNumberModel numberModel = new SpinnerNumberModel(1, 0, 10, 1);
		JSpinner spinner_NumberModel = new JSpinner(numberModel);
		contentPane.add(spinner_NumberModel);
		
		//DateModel
		Calendar cal = Calendar.getInstance();
		Date value = cal.getTime(); 
		
		cal.add(Calendar.YEAR, -50);
		Date start = cal.getTime(); //최소날짜
		cal.add(Calendar.YEAR, 100);
		Date end = cal.getTime(); //최대날짜
		
		SpinnerDateModel dateModel = new SpinnerDateModel(value, start, end, Calendar.YEAR);
		JSpinner spinner_DateModel = new JSpinner(dateModel);
		spinner_DateModel.setEditor(new JSpinner.DateEditor(spinner_DateModel, "yyyy/MM/dd"));
		contentPane.add(spinner_DateModel);
	}

}
